"""author: wangxin
   data: 2021/11/23
   project: homework
"""

import random
import string


def code():
    lst = []
    while 1:
        N = input("请输入激活码个数：")
        if N.isdigit():
            for i in range(int(N)):
                while 1:
                    activation_code = "".join(random.sample('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 32))
                    if activation_code in lst:
                        continue
                    else:
                        with open("code.txt", 'a') as code:
                            code.write(activation_code)
                            code.write("\n")
                        lst.append(activation_code)
                        break
            print(f"已为你生成{N}个激活码")
            break
        else:
            print("输入不合法，请重新输入")

if __name__ == "__main__":
   code()
